package com.ternnetwork.oa.repository.settings;


import com.ternnetwork.oa.entity.settings.UserRelationship;
import com.ternnetwork.oa.entity.settings.UserRelationshipId;

import com.ternnetwork.oa.enums.settings.UserRelationshipType;
import com.ternnetwork.persistence.repository.BaseRepository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRelationshipRepository extends BaseRepository<UserRelationship, UserRelationshipId> {


    @Query("from UserRelationship t where t.userFrom.id=?1 and t.type=?2")
    List<UserRelationship> findAll(Long userFromId, UserRelationshipType type);


    @Modifying
    @Query("delete from UserRelationship t where t.type=:type and t.userFrom.id=:userFromId  and t.userTo.id not in(:userToIdList)")
    Integer deleteAllByUserFromIdAndExcludeUserToIdList(UserRelationshipType type,Long userFromId, List<Long> userToIdList);

    @Modifying
    @Query("delete from UserRelationship t where t.type=:type and t.userFrom.id=:userFromId")
    Integer deleteAllByUserFromId(UserRelationshipType type,Long userFromId);







}
